package top.kaoshanji.ch02;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.ch02.serialClone.Employee;

/**
 * 代码清单 ch02-04：为克隆使用序列化示例(2.3.6节)
 * @see top.kaoshanji.ch02.serialClone.SerialCloneable 实现了Cloneable、Serializable接口
 * author kaoshanji
 * ^_^
 * create time 2024/12/6 17:17
 */
public class SerialCloneTest {

    private static final Logger logger = LogManager.getLogger(SerialCloneTest.class);

    public static void main(String[] args) throws CloneNotSupportedException {
        logger.info("...代码清单 ch02-04：为克隆使用序列化示例(2.3.6节)...");

        var harry = new Employee("Harry Hacker", 35000, 1989, 10, 1);
        // 通过克隆出现了第二个对象，这是深拷贝..就是互不影响
        var harry2 = (Employee)harry.clone();

        // 修改了原始的对象
        harry.raiseSalary(10);

        // 那么，两个对应的这个属性值是不同的了..
        System.out.println(harry);
        System.out.println(harry2);

    }

}
